using Microsoft.VisualStudio.TestTools.UnitTesting;
using PsVcs;

namespace PsVcsTest
{
    /// <summary>
    /// Summary description for ConferenceManagerTest
    /// </summary>
    [TestClass]
    public class ConferenceManagerTest
    {

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestAddValid()
        {
            ConferenceManager confMgr = GetConfMgr();
            Conference conf = new Conference("PRJ1", 12.0);

            confMgr.Add(conf);
            Assert.AreEqual(1,confMgr.Conferences.Count,"TestAddValid.ConferenceCount.After");
            Assert.IsNotNull(confMgr.WorkingConference,"TestAddValid.WorkingConference.After");
        }

        [TestMethod]
        [ExpectedException(typeof(PsVcsException), PsVcsException.ConferenceManagerNullConferenceAdded)]
        public void TestAddNull()
        {
            ConferenceManager confMgr = GetConfMgr();
            confMgr.Add(null);
        }

        private static ConferenceManager GetConfMgr()
        {
            ConferenceManager confMgr = new ConferenceManager();
            Assert.AreEqual(0, confMgr.Conferences.Count, "GetConfMgr.ConferenceCount.Before");
            Assert.IsNull(confMgr.WorkingConference, "GetConfMgr.WorkingConference.Before");
            return confMgr;
        }

        [TestMethod]
        [ExpectedException(typeof(PsVcsException), PsVcsException.ConferenceManagerDuplicateConferenceAdded)]
        public void TestAddDuplicate()
        {
            ConferenceManager confMgr = GetConfMgr();
            Conference conf = new Conference("PRJ1", 12.0);

            confMgr.Add(conf);
            Assert.AreEqual(1, confMgr.Conferences.Count, "TestAddDuplicate.ConferenceCount.Before");
            Assert.IsNotNull(confMgr.WorkingConference, "TestAddDuplicate.WorkingConference.Before");
            
            confMgr.Add(conf);
        }
    }
}
